<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Auth;
class LoginController extends Controller{
	function login(){
		$this->display();
	}

	function Verify(){
       ob_clean();
       $ob=new \Think\Verify();
       $ob->fontSize=15;
       $ob->length=1;
       $ob->imageH=40;
       $ob->imageW=180;
       $ob->entry();
	}

	function check(){
		$username=$_POST["username"];
		$password=$_POST['password'];
		$vcode=$_POST["vcode"];
		$online=$_POST["online"];
		$yanzheng=new \Think\Verify();
		$re=$yanzheng->check($vcode);
		$mo=M('Admin');
		$re1=$mo->where("username='{$username}' and password='{$password}'")->find();
		if ($re) {
			if ($re1) {
				$userid=$re1["id"];
				if ($online==1) {
				$this->redirect("Admin/Index/index");
				setcookie("adminid",$userid,time()+3600*30,'/');
				setcookie("username",'$username',time()+3600*30,'/');
				}else{
					$this->success("登录成功",U("Admin/Index/index"));
					setcookie("adminid",$userid,0,'/');
					setcookie('username','$username',0,'/');
				}
			}else{
				$this->success("账号密码错误",U("Admin/Login/login"));
			}
		}else{
			$this->success("登录失败，验证码错误",U("Admin/Login/login"));
		}
	}

}